# -*- coding: utf-8 -*-
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule


class TtSpider(CrawlSpider):
    name = 'tt'
    allowed_domains = ['tencent.com']
    start_urls = ['https://careers.tencent.com/search.html?pcid=40001']

    rules = (
        #进入详情页
        Rule(LinkExtractor(allow=r'position_detail\.php\?id=\d+keyword=&tid=0&lid=0'), callback='parse_item'), # 注意问号和点号的转义“\”，尽管在钱买你已经写了r
        #自动翻页
        Rule(LinkExtractor(allow=r'position.php?&start=\d+#a'), follow=True),
    )

    def parse_item(self, response):
        item = {}
        item["title"] = response.xapath('//td[@id="sharetitle"]/text()').extract_first()
        item["acquire"] = response.xpath('//div[text()="工作要求："]/../ul/li/text()').extract()
        # return item
        print(item)

"""
注意1：腾讯现在链接（岗位+下一页）都没有直接显示在源码中
注意2：源码中相当一部分是被注释掉了（同百度贴吧），用户代理应该使用IE的用户代理
"""